home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 1.iso / ARGONET / PD / MATHS / RLAB / RLAB125.ZIP / !RLaB / help_jr / local < prev    next >
Text File  |  1994-10-08  |  1KB  |  46 lines

  1. local
  2.  
  3. Syntax:    local ( VAR1 , VAR2 , VAR3, ... )
  4.  
  5. Description:
  6.  
  7.     The local statement forces a function to resolve specified
  8.     variable reference within the function itself. Each local
  9.     variable is initialized UNDEFINED, and is destroyed after
  10.     execution leaves the function. Each time execution enters the
  11.     function, the local variables are re-initialized.
  12.  
  13.     Declaring argument variables local copies the value of the
  14.     argument variable into the local variable of the same
  15.     name. The argument variable is not accessible while function
  16.     is executing. In essence, this procedure forces arguments to
  17.     be passed by value.
  18.  
  19.     For example:
  20.  
  21.     mgs = function(A)
  22.     {
  23.       local (A)
  24.       m = A.nr;  n = A.nc;
  25.       for(k in 1:n)
  26.         {
  27.           r[k;k] = norm( A[1:m;k], "2");
  28.           q[1:m;k] = A[1:m;k]/r[k;k];
  29.           for(j in k+1:n)
  30.         {
  31.           r[k;j] = q[1:m;k]' * A[1:m;j];
  32.               A[1:m;j] = A[1:m;j] - q[1:m;k] * r[k;j];
  33.             }
  34.          }
  35.       return << q = q; r = r >>;
  36.     };
  37.  
  38.  
  39.     The function `mgs' uses the local statement to forces
  40.     pass-by-value on its argument `A'. Since A is passed to the
  41.     function by value, modification of A will not affect the
  42.     original variable. `A' is modified within the for-loop without
  43.     affecting the original function argument.
  44.  
  45. See Also: FUNCTION, global, static
  46.